package com.twu.bibilioteca;

import com.sun.tools.corba.se.idl.InvalidArgument;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: dixithk
 * Date: 6/12/14
 * Time: 2:31 PM
 * To change this template use File | Settings | File Templates.
 */
public class Application {




    public static  void main(String[] args) throws InvalidArgument {
        UserInterface ui = new UserInterfaceApp();
        Menu menu = new Menu();
        Library lib = new Library();
        lib.loadBooks();



        List<MenuOperations> availableOptions = new ArrayList<MenuOperations>();

        availableOptions .add(new ListAllBooks(ui, lib));
       availableOptions .add(new CheckOutBook(ui, lib));
        availableOptions .add(new ReturnBook(ui, lib));
        availableOptions .add(new MenuOperations() {


            @Override
            public Result action() {
                return new Result("quit", true);  //To change body of implemented methods use File | Settings | File Templates.
            }

            @Override
            public String getName() {
                return "quit";  //To change body of implemented methods use File | Settings | File Templates.
            }
        });
        
        
        
        



        ui.display("Welcome To Digital Library System");
        List<String> menuOptions= menu.setOptions(availableOptions );

        while(true)
        {

             ui.displayMenuOptions(menuOptions);

            try
            {
                int choice = Integer.parseInt(ui.takeUserChoice()) ;
                menu.isValidOption(choice);
                Result c =(availableOptions .get(choice - 1)).action() ;
                ui.printConclusion(c);
                if(c.getAnswer().equals("quit"))
                {
                    break;
                }
            }
            catch(NumberFormatException e)
            {
                ui.display("Invalid Option\n");
            }





        }

    }


}
